package com.example.restaurant.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.restaurant.common.Log;
import com.example.restaurant.common.Result;
import com.example.restaurant.controller.form.AddDeskForm;
import com.example.restaurant.controller.form.GetDeskForm;
import com.example.restaurant.controller.form.PutDeskForm;
import com.example.restaurant.model.Desk;
import com.example.restaurant.service.DeskService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 桌表 前端控制器
 * </p>
 *
 * @author x
 * @since 2022-09-29
 */
@RestController
public class DeskController {

    @Resource
    private DeskService deskService;

    //新增
    @PostMapping("/addDesk")
    public Result addDesk(@Valid @RequestBody AddDeskForm addDeskForm){
        boolean b = deskService.addDesk(addDeskForm);
        return Result.success();
    }

    //删除
    @DeleteMapping("/delDesk")
    public Result delDesk(int deskId){
        boolean b = deskService.delDesk(deskId);
        return Result.success();
    }

    //查询
    @GetMapping("/getDeskByPage")
    @Log
    public Result getDeskByPage(Integer storeId,String deskName,@RequestParam(defaultValue = "1")Integer current,@RequestParam(defaultValue = "5")Integer size){
        Page<Desk> desks = deskService.getDeskByStoreId(storeId,deskName,current,size);
        return Result.success(desks);
    }
    //修改
    @PutMapping("putDesk")
    @Log
    public Result putDesk(@RequestBody @Valid PutDeskForm putDeskForm){
        boolean b = deskService.putDesk(putDeskForm);
        return Result.success();
    }

    //通过门店ID查询桌子
    @GetMapping("/getDeskByStoreId")
    public Result getDeskByStoreId(Integer storeId){
        List<Desk> deskByStoreIda = deskService.getDeskByStoreIda(storeId);
        return Result.success(deskByStoreIda);
    }

}
